package com.loong.controller;

import com.loong.pojo.PageBean;
import com.loong.pojo.Product;
import com.loong.service.ProductService;
import com.loong.service.impl.ProductServiceImpl;
import com.loong.utils.Constants;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet("/product")
public class ProductController extends BaseServlet{
    public String show(HttpServletRequest request, HttpServletResponse response){
        String tid = request.getParameter("tid");
        //从前端获取当前页数和页容量
        int pageSize = 8;
        String currentPage = request.getParameter("currentPage");
        int page = 1;
        if(currentPage!= null){
            page = Integer.parseInt(currentPage);
        }
        ProductService productService = new ProductServiceImpl();
        PageBean<Product> pageBean = productService.findPage(tid,page,pageSize);
        System.out.println(pageBean);

        request.setAttribute("pageBean",pageBean);
        return Constants.FORWARD + "goodsList.jsp";
    }

    public String  detail(HttpServletRequest request, HttpServletResponse response){
        int pid = Integer.parseInt(request.getParameter("pid"));
        ProductService productService = new ProductServiceImpl();
        Product product = productService.findProductByPid(pid);
     request.setAttribute("product",product);
        return Constants.FORWARD + "goodsDetail.jsp";
    }
}
